// pages/Index/shopActive/group/detail.js
const controllers = require('../../../controllers/controllerIndex').controller
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail:{},
    ischecked:false,
    imgurl:'',
    link:""
  },
  //更新拼团状态
  switch(e){
    controllers.updateButton({
      marketId:this.data.detail.id,
      shopId:wx.getStorageSync('shopId')
    }).then(res =>{
      console.log(res);
      
    })
  },
  //删除过期活动
  delete(){
    controllers.deleteGruop({
      marketId:this.data.detail.id,
      shopId:wx.getStorageSync('shopId')
    }).then(res =>{
      wx.showToast({
        title: '删除成功',
        icon:'none',
        duration:1000
      })
      setTimeout(function(){
        wx.navigateBack({
          delta: 1,
        })
      },1500)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    this.setData({
      imgurl:app.globalData.IMG_URL
    })
    controllers.getGroupDetail({
      marketId:options.id
    }).then(res =>{
      this.setData({
        detail:res.data
      })
      if(res.data.buttonState==1){
        this.setData({
          ischecked:true
        })
      }
      that.getcode()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }


  //获取二维码链接
  getcode(){
    let shopId=wx.getStorageSync('shopId');
    let marketId=this.data.detail.id;
    let page="pages/Mall/Grouplists";
    let scene="marketId:"+marketId+","+"shopId:"+shopId;
    controllers.getCode({shopId:shopId,page:page,scene:scene}).then(res=>{
      this.setData({
        link:res.data
      })
    })
  },


  toCode(){
    let link=this.data.link;
    link=encodeURIComponent(link)
    wx.navigateTo({
      url: '/pages/Index/QRCode/QRCode?link='+link,
    })
  }
})